/** Interactive Surface  FYP- 25 Interactive Surface FYP- 25 Interactive Surface FYP- 25
 *
 *  @author Acer
 */
package controller;

import UserInterface.FinalGUI;
import camera.ColorMeanCamera;
import utilities.CoordinateFinder;

/** Interactive Surface FYP- 25 Interactive Surface FYP- 25 Interactive Surface FYP- 25
 *  General Information about this class -
 *  Comments -Controls the two cameras
 */
public class ColorMeanController extends Thread {

    final int CAM_NUM1,CAM_NUM2, CAM_FOV = 84;
    CoordinateFinder coFind=new CoordinateFinder();
    // CanvasFrame canvas = new CanvasFrame("Web Cam Live");
   

    public ColorMeanController(int CAM_NUM1, int CAM_NUM2) {
        this.CAM_NUM1 = CAM_NUM1;
        this.CAM_NUM2 = CAM_NUM2;
    }

    @Override
    public void run() {

        // Initialize Cameras
        ColorMeanCamera cam1 = new ColorMeanCamera(CAM_NUM1,CAM_FOV );
        Thread th = new Thread(cam1);
        th.start();

        ColorMeanCamera cam2 = new ColorMeanCamera(CAM_NUM2,CAM_FOV );
        Thread th1 = new Thread(cam2);
        th1.start();

        int[] ty;
        double theta, beeta, gamma, delta;
        try {
            Thread.sleep(7000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
         while (true) {
            // System.out.println("Running");
            theta = cam1.getTheta();
            beeta = cam2.getTheta();
            gamma = Math.toRadians(90) - theta;
            delta = Math.toRadians(90-CAM_FOV) + beeta;
            ty = coFind.getCoordinate(1, gamma, delta);
            //System.out.println("Final Coordinate= x=" + ty[0] + " y= " + ty[1]);
            FinalGUI.setX_Y(ty[0], ty[1]);
        }
    }

}

